<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
  
        var romanToInt = function(s){
            var obj = {
            'I': 1,
            'V': 5,
            'X': 10,
            'L': 50,
            'C': 100,
            'D': 500,
            'M': 1000,
        }; 
        if(s.length == 0){
            return 0;
        }
        if(s.length == 1){
            return obj[s];
        }
        var res =  0;
        for(var i =0;i<s.length;i++){
            if(obj[s[i]]<obj[s[i+1]]){
                res +=obj[s[i+1]]-obj[s[i]];
                i++;
            }
            else{
                res +=obj[s[i]];
            }
        }
        return res;
        }
        r = romanToInt('IV');
        console.log(r)
    </script>
</body>
</html>